package sleuthkit.gui.actionlistener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;

import org.apache.log4j.Logger;

import sleuthkit.gui.MainApplication;

public class MyActionListener implements ActionListener {

	private JComboBox comboBox;
	private MainApplication parent;
	private JButton btnCreate;
	private Logger log = Logger.getLogger(MyActionListener.class);

	public MyActionListener(JComboBox comboBox, MainApplication parent) {
		super();
		this.comboBox = comboBox;
		this.parent = parent;
		//this.btnCreate = parent.getBtnCreate();
	}

	public void actionPerformed(ActionEvent arg0) {
		if (null != parent && null != comboBox) {
			this.btnCreate = parent.getBtnCreate();
			if (null != btnCreate) {
				if (comboBox.getSelectedIndex() > 0){
					log.debug("A existing case is selected");
					btnCreate.setText("Open..");
					btnCreate.setEnabled(true);
					// load the investigators name
				} else  {
					if (((String)comboBox.getSelectedObjects()[0]).equalsIgnoreCase("")) {
						btnCreate.setEnabled(false);
					} else {
						btnCreate.setText("Create..");
						btnCreate.setEnabled(true);
					}
				}
			}
		}
	}
}
